#ifndef DRV_H
#define DRV_H
#define RBUF_SIZE   		256 
#define SIO_COMMAND_LEN         30
#define UART2_MAX_SIZE          256
#define UART1_MAX_SIZE          256

#define UART2_TIME              500        //200*50ms
#define UART2_TIME_NUM          1        
#define SENDKEEP_TIME           10000        //200*50ms
#define SENDKEEP0_TIME_NUM      2
#define SENDKEEP1_TIME_NUM      3
#define RESERVE_TIME            10000        //200*50ms
#define SOCKET0_TIME_NUM        4  
#define SOCKET1_TIME_NUM        5
#define SOCKET2_TIME_NUM        6
#define DELAY_TIME_NUM          9

#define AFDX_STAT           GPIO_Pin_4 
#define AFDX_STAT_GPIO      GPIOD
#define Get_AFDX_Stat       AFDX_STAT_GPIO->IDR & AFDX_STAT//GPIO_ReadInputDataBit(GPIOB,AFDX_STAT)

#define XRUN_STEP          8000
#define YRUN_STEP          8000
#define START_SPEED         100
#define STOP_SPEED          100
#define MAX_SPEED          1000
#define ACC_SPEED          100

#define TypeAdr                 0
#define TypeAdrLen              2
#define PenCutParameterAdr      16
#define PenCutParameterAdrLen   60
typedef struct{
        unsigned int m_XYSpeed[3];	
        unsigned int ZPenSpeed;
	unsigned int ZHalfKnifeSpeed;
	unsigned int ZKnifeSpeed;
        unsigned int m_ZLen[3];	
        unsigned int XPosStart;
	unsigned int YPosStart;
	unsigned int XPosStop;
	unsigned int YPosStop;
        int m_XDev;
	int m_YDev;
        unsigned int stop_posi;        
        int com_baud;
        unsigned char CurLanguage;
}PenCutParameter;

#define PenCutType      2
typedef struct{
    int XLen;
    int YLen;
}PenCutSize;
extern const PenCutSize m_PenCutSize[PenCutType];

extern volatile int m_CurXSize;
extern volatile int m_CurYSize;
extern volatile int m_ZeroX;
extern volatile int m_ZeroY;

extern volatile unsigned char m_Init;
extern volatile unsigned char m_Plotting;
extern volatile PenCutParameter m_PenCutPar;
extern volatile char rbuf3[RBUF_SIZE];
extern volatile unsigned char r_in3;
extern volatile unsigned char r_out3;

extern volatile unsigned char   r_in1, r_out1;
extern volatile unsigned char  rbuf1[UART1_MAX_SIZE];

extern volatile unsigned char   r_in2, r_out2;
extern volatile unsigned char  rbuf2[UART2_MAX_SIZE];
extern volatile unsigned int Timer2TotalCnt;
extern volatile unsigned char m_Out4;
extern volatile unsigned char m_SelF;
extern volatile unsigned char m_Down;

void Hardware_Init(void);
void Timer2_Process(void);

void Delay(unsigned int X1ms);
void StartDelayTime(unsigned char num);
unsigned int GetDealyTime(unsigned char num);

void USART3_Init(void);
unsigned char Usart3_get_frame(char *buf,unsigned char len);
void Usart3_put_String(char *buf,unsigned int len);
void Uart2_Process();
void AFDX_init();
unsigned char Write_PenCutParameter(int aaa);
unsigned char Reset_PenCutParameter(int aaa);
unsigned char KnifePenTest(int aaa);
unsigned char Uart1_Get_Stat(char *Src,unsigned char Len);
void XYRun(unsigned char flag);
unsigned char Uart1_Send_Command(char *Src,unsigned char Len);
void ZRun();
#endif
